package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.AlertDataHandleDto;
import com.zzyl.entity.AlertData;
import com.zzyl.mapper.AlertDataMapper;
import com.zzyl.service.AlertDataService;
import com.zzyl.vo.AlertDataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AlertDataServiceImpl implements AlertDataService {
    @Autowired
    private AlertDataMapper alertDataMapper;

    @Override
    public PageResponse<AlertDataVo> getAlertDataPage(Integer pageNum, Integer pageSize, String deviceName, Long endTime, Long id, Long startTime, Integer status) {
        PageHelper.startPage(pageNum, pageSize);
        Page<AlertData> page = (Page<AlertData>) alertDataMapper.getAlertDataPage(deviceName, endTime==null?null:LocalDateTimeUtil.of(endTime), id, startTime==null?null:LocalDateTimeUtil.of(startTime), status);
        return PageResponse.of(page, AlertDataVo.class);
    }

    @Override
    public void handleAlertData(AlertDataHandleDto alertDataHandleDto, Long id) {
        AlertData alertData = BeanUtil.copyProperties(alertDataHandleDto, AlertData.class);

        alertDataMapper.handleAlertData(alertData,id);
    }


}
